package com.lkm.app_ui.ui.fj;

import androidx.annotation.NonNull;

import com.lkm.javatool.CollectionHelp;
import com.lkm.javatool.StringHelp;
import com.lkm.market2_0.help.SteelardHelp;
import com.lkm.market2_0.m.steelyarddata.OrderEntity;

import java.util.List;



public class FjOrder {

    public FjOrder(String address, List<FjItem> fjItems, String fjInfoNo, String createTime) {
        this.address = address;
        this.fjItems = fjItems;
        this.fjInfoNo = fjInfoNo;
        this.createTime = createTime;
    }



    @NonNull
    public List<FjItem> fjItems;



    public String fjInfoNo;



    public String createTime;

    public String address;

    public FjItem getByIndex(int index) {
        try {
            return fjItems.get(index);
        } catch (Exception e) {

        }
        return null;
    }



    public FjItem findNext(FjItem fjItem) {

        if (fjItems == null) return null;
        int startIndex = 0;
        if (fjItem != null)
            for (int i = 0; i < fjItems.size(); i++) {
                FjItem item = fjItems.get(i);
                if (StringHelp.equals(item.id, fjItem.id)) {
                    startIndex = i;
                    break;
                }

            }

        for (int i = startIndex; i < fjItems.size(); i++) {
            FjItem item = fjItems.get(i);
            if (!item.isOK()) {
                return item;
            }
        }

        return null;

    }

    public float totalPrice(){
        float totalPrice = 0.0f;
        if(!CollectionHelp.isEmpty(fjItems))
            for (FjItem ge : fjItems) {
                totalPrice += ge.calPrice();//SteelardHelp.formatMoneyFloat(ge.unitPrice * ge.weight);
            }
        return totalPrice;
    }


    public static class FjItem {



        public String createTime;

        public String fjInfoNo;

        public FjItem(String fjInfoNo,String createTime, String id, String goodsName, float price, String weight, float offess) {
            this.id = id;
            this.goodsName = goodsName;
            this.price = price;
            this.weight = weight;

            this.fjInfoNo = fjInfoNo;
            this.createTime = createTime;
        }



        public String getUnStr() {
            return id + "-" + goodsName + "-" + price + "-" + weight;

        }


        public String img_on;

        public String id;

        public String goodsName;



        public float price;



        public String weight;








        public String realWeight;



        public boolean isOK() {
            return !StringHelp.isEmpty(realWeight);
        }


        public float calPrice() {
            return SteelardHelp.calPrice(""+price, realWeight);
        }

    }
}
